import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    component: () => import('@/views/Home/Home.vue'),
    meta: {
      isRecord: true,
      top: 0
    }
  },
  {
    path: '/user',
    component: () => import('@/views/User/User.vue')
  }
  // component: () => import('../views/AboutView.vue')
]

const router = new VueRouter({
  routes,
  // 滚动条位置
  scrollBehavior(to, from, savedPosition) {
    // return 期望滚动到哪个位置
    if (savedPosition) {
      // 如果记录了页面位置
      return savedPosition
    } else {
      // 如果没有记录那就返回一个默认x为0，y为记录的，没有记录的也为0
      return { x: 0, y: to.meta.top || 0 }
    }
  }
})

export default router
